package com.forcht.client.handle.impl;

import com.forcht.client.Client;
import com.forcht.client.handle.ResponseHandler;
import com.forcht.client.view.ChatView;
import com.forcht.common.domain.Response;
import com.forcht.common.domain.ResponseHeader;
import org.springframework.stereotype.Component;

/**
 * Created by forcht on 2018/4/15.
 * 接收好友消息
 */
@Component("messageHandler.chat_one")
public class ChatOneMessageHandler extends ResponseHandler {
    @Override
    public void handle(Response response, Client client) {
        //解析response
        ResponseHeader header = response.getHeader();
        System.out.println(response);
        String sender = header.getSender();
        byte[] body = response.getBody();
        //获取聊天面板
        ChatView chatView = client.getChatView(sender);
        if(chatView==null){
            chatView = new ChatView(client,sender);
            client.addChatView(sender,chatView);
        }
        //更新聊天内容
        chatView.updateContentArea(new String(body));
    }
}
